<?php $this->load->helper('form');?>
<!DOCTYPE html>
<html>
	<head>
		<title><?php echo $title;?></title>
		<?php echo link_tag('css/ppharm_popup.css'.'?'.time());?>  
		<?php echo link_tag('css/custom-theme/jquery-ui-1.8.2.custom.css'.'?'.time());?>
		<script type="text/javascript" src="<?php echo base_url().('/js/jquery.min.js');?>"></script>
		<script type="text/javascript" src="<?php echo base_url().('/js/jquery-ui.min.js');?>"></script>
		<script type="text/javascript" src="<?php echo base_url().('/js/common_form_functions.js').'?'.time();//TODO:  Version this once complete. Must timestamp so it will always update from cache?>"></script>
		<script type="text/javascript">
			$(document).ready(function() {	
					$("#_close").click(function() {
							window.opener.location.reload();
							window.close();
							return false;
							});

					 $('#copy-intervention-dialog-message').dialog({
						 autoOpen: false,modal: true, width:500, height:350, show: 'blind',buttons: {Ok: function() {$(this).dialog('close');}}
					 });

					 $('.ui-state-default').hover(
							 function(){ $(this).addClass('ui-state-hover'); }, 
							 function(){ $(this).removeClass('ui-state-hover'); }
						 );

					 $('.ui-state-default').click(function(){
						$('#copy-intervention-dialog-message').dialog('open');
						return false; 
					 });

					 $('#_optCopyToNextMonth').click(function(){
							$('#_day').attr("disabled", true);
						 	$('#_months').attr("disabled", true);
						 	$('#_year').attr("disabled", true); 
						 });

					 $('#_optSpecifyDate').click(function(){
						 	$('#_day').attr("disabled", false);
						 	$('#_months').attr("disabled", false);
						 	$('#_year').attr("disabled", false);
						 });

					 $('#_copy').click(function(){
						 copy_intvention();
					 });

					function copy_intvention()
					{
						$('#_copy').attr('disabled', true);
						$('#_copy').val('Please wait...'); 
						var dateboxValue = $('#_months').val() + '_' + $('#_day').val() + '_' + $('#_year').val();
						if (!isDate(dateboxValue.replace(/_/g,'/')))
						{
							window.alert('Date is not valid');
							$('#_day').focus();
							return false;
						}
						
						var ciId = $('input[name=intervention_ids]').val();
					 	var dateTicks = String(Number(new Date())); //Must append Date Ticks as a segment to the URL so IE wont' cache the Ajax link
					 	returnedData = $.ajax({
					 	      url: my_url() + '/ajax/copy_intervention/' + dateTicks + '/' + $('#_optCopyToNextMonth').attr('checked') + '/' + dateboxValue + ciId,
					 	      global: false,
					 	      dataType: 'html',
					 	      async:false
					 	   }
					 	).responseText;
					 	$('#_copy').val('Finished.');
					 	window.alert(returnedData);
					 	$('#_close').click();
					 	return false;
					 }

					
					<?php echo isset($additional_javascript_doc_ready_functions) ? $additional_javascript_doc_ready_functions : '' ; ?>

					$('#_optCopyToNextMonth').click();
		});
		
		<?php echo isset($additional_jquery_javascript) ? $additional_jquery_javascript : '' ; ?>

		function my_url()
		{
			return '<?php echo site_url(); //Needed to reference website from javascript?>';
		}
		</script>
		
		<style type="text/css">
			.copy-date-box
			{
				text-align: right;
				width:		50px;
			}
		</style>
	</head>

	<body>
		<div class = "ppg-logo">
			<image src="<?php echo base_url().'/images/comp_logo.jpg';?>"/>
		</div>
		<div class="facility-name">
			<span style="padding-right: 100px; font-family: Arial, 'Trebuchet MS', sans-serif; font-size: 22px;">
				<?php echo $heading;?><div id="_interventionCopyHelpDiv" class="ui-state-default ui-corner-all" style="float:left;"><span class="ui-icon ui-icon-help"></span></div>
			</span>
			<?php echo $user_facility_name;?>
		</div>
		<div class = "clear-class"></div>
	
	<?php echo form_fieldset('','class = "small-popup-frameset"');?>
	<?php echo form_hidden('intervention_ids', $copy_ids);; ?>
	
	<?php 
	$this->load->helper('form');
	$intervention_count = substr_count($copy_ids,'/');
	echo '<h3>You have selected '.$intervention_count.' intervention'.($intervention_count == 1 ? '' : 's').' to copy to the date specified below.</h3>';
	?>
	
	<?php echo form_fieldset('Intervention Date Option');?>
		<div >
			<div style = "width:130px;float:left;">
				<?php 	echo form_radio($opt_copy_to_next_month).'Copy to Next Month<br>';
						echo form_radio($opt_specify_date).'Specify Copy Date';
				?>
			</div>
			<div style	=	"float:left;padding-top:10px;padding-bottom: 5px;">
				<?php 	echo form_fieldset('');
							echo form_dropdown('months', $month_list, date('m') + 1 ,'id="_months"');
						 	echo '&nbsp;&nbsp;/&nbsp;&nbsp;';?>
						 	<input type="text" class = "copy-date-box" id="_day" disabled="disabled"autocomplete="off" value="1" MAXLENGTH=2/>
						 	<?php echo '&nbsp;&nbsp;/&nbsp;&nbsp;';?>
						 	 <input type="text" class = "copy-date-box" id="_year" autocomplete="off" MAXLENGTH=4 value="<?php echo date('Y');?>"/>
				 <?php echo form_fieldset_close();?>
			</div>
		</div>
	<?php echo form_fieldset_close(); //Intervention Date Option ?>
	
	<div class="small-popup-button-class"> 
		<input name="copy" id="_copy" type="submit"	style="width:120px;" value="Copy Interventions"/>
		<button name="close" id="_close" />Close</button>
	</div>
	<?php echo form_fieldset_close(); //Small Pop-up Fieldset ?>
	
		
	<div class="clear-class"></div>
	
		<div id="copy-intervention-dialog-message" title="Copy Intervention">
			<p>
				Use this form to Copy Interventions from one month to another. <br><br>
				<ol>
					<li>Select Intervention Date Option: </li>
						<ol>
					    <li>Keep Date:  The date the invention occurred will remain.   
					                      Only the month will change. (e.g. 05/12/2010 will copy as 06/12/2010) </li>
					    <li>Specify Date:  The date specified in the Date Box will be copied to ALL interventions. 
					                      The month and day will be the one specified in the date box. </li>
					    </ol>
					<li>Select Copy Button </li>
				</ol>
					<br>
				  <b>NOTE:</b>  The month you specify in the date box is the month the interventions will be copied.   <br>
				  <br><b>NOTE:</b>  Intervention dates that cannot copy directly (e.g. January 31st cannot copy to February 31st), will copy to the last day of the month. <br>
			</p>
		</div>
	</body>
</html>
